home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / MacTutor Help Source / Code Resource Version / Pascal Example / dispatcher.p next >
Encoding:
Text File  |  1989-08-29  |  2.1 KB  |  107 lines  |  [TEXT/MPS ]

  1. {$S Dispatcher}
  2.  
  3. (* ------------------------------------------------- *)
  4. (*                  DISPATCHER  UNIT                 *)
  5. (* ------------------------------------------------- *)
  6. (* Purpose: Channel all menu actions to their dest-  *)
  7. (*          ination.  In particular, notice the       *)
  8. (*          INLINE function necessary to get Pascal  *)
  9. (*          to call MacTutor Help.                   *)
  10. (* ------------------------------------------------- *)
  11.  
  12. UNIT Dispatcher;
  13.  
  14. INTERFACE
  15.  
  16. USES
  17.     MemTypes,QuickDraw,OSIntf,ToolIntf,PackIntf, Resources,
  18.     Utilities;
  19.  
  20. CONST
  21.     MBarID        =    256;
  22.     AppleID        =    256;
  23.     FileID        =    257;
  24.     EditID        =    258;
  25.     HelpItem        =    1;
  26.     QuitItem        =    2;
  27.     AboutItem    =    1;
  28.     OK_Button    =    1;
  29.     AboutWIndow    =    400;
  30.     
  31. PROCEDURE Handle_My_Menu(var doneFlag:boolean; theMenu,theItem:integer);
  32.  
  33. IMPLEMENTATION
  34.  
  35. PROCEDURE  Call_Code(routine: Ptr);
  36.     INLINE    $205F,        { MOVEA.L    (A7)+,A0     }
  37.                 $4E90;        { JMP            (A0)         }
  38.  
  39. PROCEDURE Handle_My_Menu;
  40.     
  41.     VAR
  42.         DNA             : integer;
  43.         BoolHolder     : boolean;
  44.         DAName         : Str255;
  45.         thePtr        : DialogPtr;
  46.         savePort        : GrafPtr;
  47.         whatHit        : integer;
  48.         ticks            : longint;
  49.         h                : Handle;
  50.         
  51.     BEGIN
  52.         CASE theMenu OF
  53.             AppleID:
  54.                 CASE theItem OF
  55.                     AboutItem:
  56.                         BEGIN
  57.                             thePtr := GetNewDialog(AboutWindow, NIL, Pointer(-1));
  58.                             CenterWindow(thePtr,0);
  59.                             ShowWindow(thePtr);
  60.                             SelectWindow(thePtr);
  61.                             SetPort(thePtr);
  62.                             BoldButton(thePtr,OK_Button);
  63.                              ModalDialog(NIL,whatHit); 
  64.                             DisposDialog(thePtr);
  65.                         END;
  66.                             
  67.                     otherwise
  68.                         BEGIN
  69.                             GetPort(SavePort);
  70.                             GetItem(GetMHandle(AppleID), theItem, DAName);
  71.                             DNA := OpenDeskAcc(DAName);
  72.                             SetPort(SavePort);
  73.                         END;
  74.                 END;
  75.             
  76.             FileID:
  77.                 CASE theItem OF
  78.                     HelpItem:
  79.                         BEGIN
  80.                             h := GetResource('HELP',128);
  81.                             if ((ResError = noErr) AND (h <> NIL)) THEN
  82.                                 BEGIN
  83.                                     HLock(h);
  84.                                     Call_Code(h^);
  85.                                     HUnlock(h); 
  86.                                 END
  87.                             ELSE
  88.                                   SysBeep(1);
  89.                         END;
  90.                         
  91.                     QuitItem:
  92.                         BEGIN
  93.                             Delay(8,ticks);
  94.                             FlashMenuBar(FileID);
  95.                             doneFlag := TRUE;
  96.                         END;
  97.                         
  98.                     otherwise;
  99.                 END;
  100.                     
  101.             otherwise;
  102.         END;
  103.         HiliteMenu(0);
  104.     END;
  105. END.
  106.  
  107.